<?php

namespace Houdunwang\Mini\Auth;

use Http;
use Illuminate\Http\Client\RequestException;

trait Base
{
    /**
     * 获取OPENID
     * @param string $code
     * @return mixed
     * @throws RequestException
     */
    public function getOpenidByCode(string $code)
    {
        $response = Http::get($this->api . "/sns/jscode2session?appid=" . $this->config('appid') . "&secret=" . $this->config('secret') .
            "&js_code={$code}&grant_type=authorization_code")
            ->throw()->json();
        return $response;
    }
}
